using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace InduMall.Core.Models.Mapping
{
    public class CategoryMap : EntityTypeConfiguration<Category>
    {
        public CategoryMap()
        {
            // Primary Key
            this.HasKey(t => t.CategoryId);

            // Properties
            this.Property(t => t.CategoryId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Title)
                .IsRequired()
                .HasMaxLength(32);

            // Table & Column Mappings
            this.ToTable("Category");
            this.Property(t => t.CategoryId).HasColumnName("CategoryId");
            this.Property(t => t.Title).HasColumnName("Title");
            this.Property(t => t.ParentId).HasColumnName("ParentId");
            this.Property(t => t.CategoryType).HasColumnName("CategoryType");

            // Relationships
            this.HasRequired(t => t.Category2)
                .WithMany(t => t.Category1)
                .HasForeignKey(d => d.ParentId);

        }
    }
}
